//获取应用实例
const app = getApp();
// 引入AES.js
var baseJs = require("../../common/base.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    businessId: 0,
    uid: "",
    userType: "",
    // 页数
    pageIndex: 1,
    // 上拉加载数组
    onReachBottomData: [],
    resultMsg: "",
    state: '',
    imgListB: [],
    images:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    this.setData({
      uid: wx.getStorageSync('uid'),
      userType: wx.getStorageSync('userType'),
      businessId: options.businessId,
    })
    this.GetEvaluationList();
  },
  // 获取评价列表
  GetEvaluationList: function () {
    var that = this;
    var businessId = this.data.businessId;
    var pageIndex = this.data.pageIndex;
    var onReachBottomData = this.data.onReachBottomData;
    var imgListB = this.data.imgListB;
    // var state = this.data.state;
    console.log("method=GetEvaluationList&SJID=" + businessId + "&PageIndex=" + pageIndex + "&PageSize=" + 20 + "&CheckType=" + 0);
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=GetEvaluationList&SJID=" + businessId + "&PageIndex=" + pageIndex + "&PageSize=" + 20 + "&CheckType=" + 0),
      success: function (res) {
        var json = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
        console.log(json);
        for (var i = 0; i < json.length; i++) {
          onReachBottomData.push(json[i])
          that.setData({
            onReachBottomData: onReachBottomData,

          })
        }
        // 图片数组
        // var jsonA = JSON.parse(baseJs.decryUrl(res.data)).ResultData.Images.split(';');
        // for (var i = 0; i < jsonA.length; i++) {
        //   if (jsonA[i].length > 0) {
        //     imgListB.push(jsonA[i]);
        //     that.setData({
        //       imgListB: imgListB,
        //     })
        //     console.log(imgListB)
        //   }
        // }
        if (json.length == 20) {
          that.setData({
            state: 'loadMore',
          })
        } else if (json.length == 0 && pageIndex == 1) {
          that.setData({
            state: 'noData',
          })
        } else if (json.length < 20) {
          that.setData({
            state: 'noMore',
          })
        } else if (json.length == 0 && pageIndex > 1) {
          that.setData({
            state: 'noMore',
          })
        }
      }
    })
  },
  /**
 * 页面上拉触底事件的处理函数
 */
  onReachBottom: function () {
    this.data.pageIndex++;
    this.GetEvaluationList();
  },

})